#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import requests
import json

# 检查API返回的数据结构
def check_api_data():
    api_url = "https://api.98dou.cn/api/hotlist/cls/all"
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
    }
    
    try:
        print("正在请求API...")
        response = requests.get(api_url, headers=headers, timeout=30)
        response.raise_for_status()
        
        data = response.json()
        print(f"API请求成功，状态码: {response.status_code}")
        
        # 打印响应的整体结构
        print("\n响应数据结构:")
        print(f"- success: {data.get('success')}")
        print(f"- msg: {data.get('msg')}")
        print(f"- data数组长度: {len(data.get('data', []))}")
        
        # 打印第一条数据的所有字段
        if data.get('success') and data.get('data') and len(data['data']) > 0:
            first_item = data['data'][0]
            print("\n第一条数据的字段:")
            for key, value in first_item.items():
                print(f"- {key}: {type(value).__name__}")
                if key in ['id', 'id_original']:
                    print(f"  值: {value}")
        
        # 保存原始数据到文件，便于分析
        with open('api_response_sample.json', 'w', encoding='utf-8') as f:
            json.dump(data['data'][:5], f, ensure_ascii=False, indent=2)
        print("\n已保存前5条数据到 api_response_sample.json 文件")
        
    except Exception as e:
        print(f"请求API时出错: {e}")

if __name__ == "__main__":
    check_api_data()